﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Biblioteca.Objetos;
using Pms.Utils;
using Biblioteca.Utils;

namespace SERIX
{
    public class Seguranca : System.Web.UI.Page
    {
        protected Usuario usuAut;
        public Usuario UsuAut
        {
            get { return usuAut; }
        }
        protected char _permissao;

        protected char _permissaoManut;
        public char PermissaoManut
        {
            get { return _permissaoManut; }
        }

        protected string _op;

        protected void OnLoad(EventArgs e)
        {
            if (Session.Count == 0)
            {
                Response.Redirect("~/Login.aspx");
            }
            else
            {
                usuAut = (Usuario)Session["usuario"];                
                string pagina = Page.Request.CurrentExecutionFilePath.ToString();
                pagina = pagina.Replace('/', ' ').Trim();
                _permissao = BiblioPMS.VerifiquePermissao(pagina.ToUpper(), BiblioPMS.aplicacaoSNG, usuAut.Login);
                if (_permissao.Equals(Constantes.PERM_NEGADA))
                    Response.Redirect("AcessoNegado.aspx");
                //manutenção
                pagina = pagina.ToUpper().Replace(".ASPX", "");
                pagina = pagina + "MANUT.ASPX";
                _permissaoManut = BiblioPMS.VerifiquePermissao(pagina, BiblioPMS.aplicacaoSNG, usuAut.Login);
            }
            //Arquivos MANUT
            if (Request["OP"] != null)
            {
                _op = Request["OP"];
                if ((_op.Equals("I") || _op.Equals("U") || _op.Equals("D")) && _permissao.Equals(Constantes.PERM_CONSULTA))
                {
                    Response.Redirect("AcessoNegado.aspx");
                }
            }
        }
    }
}
